package com.david.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.david.entity.Employee;
import com.david.service.Impl.EmployeeService;
import com.david.vo.CardBean;
import com.david.vo.EmployeeBean;
import com.david.vo.EmployeeCondition;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author David
 */
@RestController
@RequestMapping("/Admin")
public class EmployeeController {

    @Resource
    EmployeeService employeeService;

    /**
     * 获取所有员工信息
     * @param page 分页功能此时的页码
     * @param limit 每一页的数量限制
     */
    @GetMapping("/getAllEmployee")
    public EmployeeBean getAllEmployee(Integer page, Integer limit){
        return employeeService.getAllEmployee(page, limit);
    }

    /**
     * 添加员工
     * @param employee 输入员工信息
     */
    @SaCheckPermission("user-add")
    @PostMapping("/saveEmployee")
    public CardBean saveEmployee(@RequestBody @Validated Employee employee){
        return employeeService.saveEmployee(employee);
    }

    /**
     * 删除员工
     * @param id 提供id删除员工
     */
    @SaCheckPermission("user-delete")
    @GetMapping("/deleteEmployee/{id}")
    public CardBean deleteEmployee(@PathVariable Integer id){
        return employeeService.deleteEmployee(id);
    }

    /**
     * 批量删除员工
     * @param ids 提供员工id列表
     */
    @SaCheckPermission("user-delete")
    @GetMapping("/batchDelete/{ids}")
    public CardBean batchDelete(@PathVariable Integer[] ids){
        return employeeService.batchDelete(ids);
    }

    /**
     * 按条件查找员工
     * @param employeeCondition 输入部分信息可进行查找
     */
    @SaCheckPermission("user-find")
    @PostMapping("/findEmployeeByCondition")
    public EmployeeBean findEmployeeByCondition(@RequestBody EmployeeCondition employeeCondition){
        return employeeService.findEmployeeByCondition(employeeCondition);
    }

    /**
     * 更新员工信息
     * @param employee 输入员工id及更新的信息
     */
    @SaCheckPermission("user-update")
    @PostMapping("/updateEmployee")
    public CardBean updateEmployee(@RequestBody Employee employee){
        return employeeService.updateEmployee(employee);
    }


}
